package com.shop2cn.iapi.sellerpromotion.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.shop2cn.iapi.sellerpromotion.parameter.GetPromotionProductsBean;
import com.shop2cn.iapi.sellerpromotion.service.GetPromotionProductsCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.mongo.Shop2cnSellerPromotionInfoWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*获取促销商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPromotionProducts{
	private static GetPromotionProductsBean getpromotionproductsBean;
	private static GetPromotionProductsCall getpromotionproductsCall;
	private static Integer mchId;
	private static Shop2cnSellerPromotionInfoWapper Shop2cnSellerPromotionInfoWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取促销商品列表");
		try {
			Shop2cnSellerPromotionInfoWapper=new Shop2cnSellerPromotionInfoWapper();
			mchId=GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
		}
	}

	@Before
	public void caseUp() {
		getpromotionproductsBean=new GetPromotionProductsBean();
		getpromotionproductsCall=new GetPromotionProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpromotionproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
		try {
			Shop2cnSellerPromotionCallService.EndAllEnablePromotion(mchId);
		} catch (Exception e) {
//			e.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionProducts_001() {
		Logger.start(true,"指定商品获取促销商品列表成功");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getpromotionproductsCall.getData().getTotal(), "验证total");
			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProducts_002() {
		Logger.start(true,"全场促销获取促销商品列表成功");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
//			List<String> productIdList=new ArrayList<String>();
//			productIdList.add(productId);
//			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			//全场促销不返还
			Logger.verifyEquals(0, getpromotionproductsCall.getData().getTotal(), "验证total");
//			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
//				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
//			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProducts_003() {
		Logger.start(true,"分页获取促销商品列表成功");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
            AddAgentProductBean addAgentProductBean2 = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId2 = AddAgentProductCallService.AddAgentProduct(addAgentProductBean2);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			productIdList.add(productId2);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(1);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getpromotionproductsCall.getData().getTotal(), "验证total");
			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
				//用来确认下一个查出的是不重复
				productIdList.remove(p);
			});
			
			getpromotionproductsBean.setPageIndex(2);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getpromotionproductsCall.getData().getTotal(), "验证total");
			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProducts_004() {
		Logger.start(true,"不输入sellerid失败");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
//			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("400", getpromotionproductsCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProducts_005() {
		Logger.start(true,"不输入promotionId失败");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
//			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("400", getpromotionproductsCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProducts_006() {
		Logger.start(true,"不输入pageIndex");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
//			getpromotionproductsBean.setPageIndex(1);
			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getpromotionproductsCall.getData().getTotal(), "验证total");
			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProducts_007() {
		Logger.start(true,"不输入pageSize");
		try {
			//获取冲突商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(mchId,"AutoTestMch",false);
            String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
            
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			List<String> productIdList=new ArrayList<String>();
			productIdList.add(productId);
			createpromotionBean.setProductIdList(productIdList);
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductsBean.setSellerId(mchId);
			getpromotionproductsBean.setPromotionId(promotionId);
			getpromotionproductsBean.setPageIndex(1);
//			getpromotionproductsBean.setPageSize(10);
			getpromotionproductsCall.setData(getpromotionproductsBean);
			getpromotionproductsCall.callService();			
			Logger.verifyEquals("200", getpromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getpromotionproductsCall.getData().getTotal(), "验证total");
			getpromotionproductsCall.getData().getProductIdList().forEach(p->{
				Logger.verifyEquals(true, productIdList.contains(p), "验证结果包含商品id");
			});
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}